<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的通知</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f9f9f9;
            padding: 40px;
        }
        .card {
            margin-bottom: 20px;
            border-left: 6px solid #007bff;
        }
        .unread {
            background-color: #fffbe6;
        }
        .btn-read {
            font-size: 0.8rem;
        }
    </style>
</head>
<body>

<div class="container">
    <h2 class="mb-4">我的通知</h2>
    <a th:href="@{http://localhost:8080/planeTicket/index}">查看我的订单</a>
    <div th:if="${#lists.isEmpty(notifications)}">
        <p class="text-muted">暂无通知。</p>
    </div>

    <div class="row">
        <div class="col-md-10 offset-md-1">
            <div class="card mb-3" th:each="notification : ${notifications}">
                <div class="card-body" th:classappend="${!notification.read}? 'unread'">
                    <h5 class="card-title" th:text="${notification.title}">标题</h5>
                    <p class="card-text" th:text="${notification.content}">内容</p>
                    <p class="text-muted small">接收时间：[[${notification.getFormattedCreatedAt()}]]</p>

                    <div th:unless="${notification.read}">
                        <form th:action="@{/user/notifications/{userId}/{notificationId}/read(
                            userId=${session.userId},
                            notificationId=${notification.id})}" method="post">
                            <button type="submit" class="btn btn-primary btn-sm btn-read">查看详情</button>
                        </form>
                    </div>

                    <form th:action="@{/user/notifications/{userId}/{notificationId}/delete(
                    userId=${session.userId},
                    notificationId=${notification.id})}"
                          method="post">
                        <input type="hidden" name="_method" value="delete"/>
                        <button type="submit" class="btn btn-danger btn-sm mt-2">删除</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>
</html>
